var tops = [];
var tmp = [];

$(document).ready(function($){

	$('.item-lk').live('click',function(){
		var target = $(this).attr('target');
		
		$('html, body').animate({
			scrollTop: $("."+target).offset().top - 80
		}, 2000);
		
	});
	
	
	$.each($(".content-service").find('section'),function(x,y){
		tmp.push(
			$(y).offset().top
		);
	});
	$.each(tmp,function(x,y){
		
		tops.push({
			x:(typeof tmp[x-1] == "undefined") ? 0 : tmp[x-1],
			y:(typeof tmp[x] == "undefined") ? 5000 : tmp[x]
		})
	});
	var item = 4;
	$(window).scroll(function(e){
		item = 4;
		$.each(tops,function(x,y){
			if(x>0){
				var t = $(window).scrollTop() + 200;
				if( t < y.y  && t > y.x ){
					item = x ;
					return false;
				}
			}
			
		});
		
		
		console.log(item)
		
		var target = $("#tab"+item).attr('target');
		var index = 0;
		var defaultHeight = 50;
		$.each($(".hoz-left-menu li"),function(x,y){
			$(y).removeClass("active");
			if(target == $(y).find('a').attr('target')){
				index = $(y).find('a').attr('top');
			}
		});
		$("#tab"+item).parent().addClass("active");
		$(".icon-arrow-rg").css({
			top: index+"px"
		})
	});

});

